package com.may.nio;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.FileOutputStream;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.nio.channels.FileChannel;

/**
 * @program: com.may.netty
 * @description: 使用 FileChannel 写入文本
 * @author: Bobby.Ma
 * @create: 2020-08-02 15:15
 **/
public class NIOFileChannel01 {
    /**
     * logger
     */
    private static final Logger log = LoggerFactory.getLogger(NIOFileChannel01.class);

    public static void main(String[] args) throws IOException {
        String str = "hello，波比马";
        FileOutputStream fileOutputStream = new FileOutputStream("C:\\Users\\19167\\Documents\\read.txt");
        FileChannel fileChannel = fileOutputStream.getChannel();
        ByteBuffer byteBuffer = ByteBuffer.allocate(1024);
        byteBuffer.put(str.getBytes());
        byteBuffer.flip();
        fileChannel.write(byteBuffer);
        fileOutputStream.close();
    }
}
